package com.helehousekeeping.radiobuttonproject.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.helehousekeeping.radiobuttonproject.R;


/**
 * 作者: LeiXiaoXing on 2016/11/29 16:18
 */

public class Toast {

    public static final int LENGTH_SHORT = android.widget.Toast.LENGTH_SHORT;
    public static final int LENGTH_LONG = android.widget.Toast.LENGTH_LONG;

    private static Toast mToast;
    private static TextView tv_msg;
    private static android.widget.Toast toast;


    private Toast() {
    }

    private Toast(Context context) {
        toast = new android.widget.Toast(context);
        View view = View.inflate(context, R.layout.view_toast, null);
        toast.setView(view);
        toast.setGravity(Gravity.CENTER, 0, 0);
        tv_msg = (TextView) view.findViewById(R.id.tv_toast_msg);
    }

    public static Toast makeText(Context context, CharSequence msg, int duration) {

        if (mToast == null) {
            mToast = new Toast(context);
        }

        if (tv_msg != null) {
            tv_msg.setText(msg);
        }
        toast.setDuration(duration);

        return mToast;
    }

    public static void showShort(Context context, CharSequence msg) {
        if (mToast == null) {
            mToast = new Toast(context);
        }

        if (tv_msg != null) {
            tv_msg.setText(msg);
        }
        toast.setDuration(android.widget.Toast.LENGTH_SHORT);
        toast.show();
    }

    public static void showLong(Context context, CharSequence msg) {
        if (mToast == null) {
            mToast = new Toast(context);
        }

        if (tv_msg != null) {
            tv_msg.setText(msg);
        }
        toast.setDuration(android.widget.Toast.LENGTH_LONG);
        toast.show();
    }
    public void show() {
        toast.show();
    }

}
